import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver=webdriver.Edge()
driver.maximize_window()
driver.get('http://10.59.9.12:7001/')
# 强制等待
time.sleep(3)
# 登录
ys=driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a')
print(ys.text)
# 隐式等待
time.sleep(3)
# 用户名和密码和登录按钮
driver.find_element(By.NAME,'username').send_keys('13811033962')
time.sleep(3)
driver.find_element(By.NAME,'password').send_keys('123456')
time.sleep(8)
driver.find_element(By.CSS_SELECTOR,'.finish-btn').click()
time.sleep(3)
# 切换页面
driver.save_screenshot(driver.find_element([-1]))
time.sleep(3)
# 商品搜索  显示等待
driver.find_element(By.CLASS_NAME,'search-input').send_keys('非洲之心')
time.sleep(3)
driver.find_element(By.XPATH,'//*[@id="searchForm"]/div[2]/input').click()
time.sleep(3)
# 立即购买并下单
driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[2]/div[1]/ul/li/div[1]/span/a/img').click()
time.sleep(3)
driver.find_element(By.ID,'buy-cart').click()
time.sleep(5)
driver.find_element(By.XPATH,'//*[@id="order-button"]').click()
time.sleep(5)
# 清空退出
driver.close()